import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;

public class Test_outStream {

    public static void main(String[] args) throws IOException{
        try(OutputStream os = new FileOutputStream("out2.txt")){
            try(OutputStreamWriter oswrite = new OutputStreamWriter(os, "UTF-8")){

                try (PrintWriter writer = new PrintWriter(oswrite)){
                    writer.println("我是第一行");
                    writer.print("我是第二行\r\n");
                    writer.printf("%d: 我是第一行\r\n",1+1);
                    writer.flush();
                }
            }
        }
    }


    public static void main4(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("output.txt")) {
            String s = "你好中国";
            byte[] b = s.getBytes("utf-8");
            os.write(b);
            os.flush();
        }
    }

    public static void main5(String[] args) throws IOException{
          try (OutputStream os = new FileOutputStream("output.txt")) {
//                String s = "Nothing";
                String s = "不显示指定编码规则";
                byte[] b = s.getBytes();
                System.out.println(Arrays.toString(b));
                os.write(b);
                // 不要忘记 flush
                os.flush();
          }
    }
    
    public static void main3(String[] args) throws IOException{
        try(OutputStream os = new FileOutputStream("output.txt")){
            byte[] b = new byte[] {
                      (byte)'G', (byte)'o', (byte)'o', (byte)'d', (byte)'B',
                    (byte)'a', (byte)'d'
            };
            os.write(b, 0, 2);

            // 不要忘记 flush
            os.flush();
          }
        }

    public static void main2(String[] args) throws IOException {
        try(OutputStream os = new FileOutputStream("output.txt")) {
            byte[] b = new byte[]{
                    (byte)'G',(byte) 'o',(byte) 'o',(byte) 'd'
            };
            os.write(b);
            os.flush();
        }
    }
    public static void main1(String[] args) throws IOException {
        try(OutputStream os = new FileOutputStream("output.txt")){
            os.write('H');
            os.write('e');
            os.write('l');
            os.write('l');
            os.write('o');
            os.flush();
        }

    }


}
